package org.scboy.dbms.controller;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.dbms.service.SystemConfigService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("base/sysconfig")
@Menu("微服务管理系统.基础配置")
public class SystemConfigController {
	
	@Autowired
	SystemConfigService service;

	/**
	 * 分页查询系统配置
	 * @param request
	 * @return
	 */
	@PostMapping("page")
	@Permission("分页查询")
	public Result page(@RequestBody Model params){
		Page page=service.page(params);
		return Result.Success(page);
	}
	
	/**
	 * 更新系统配置
	 * @param request
	 * @return
	 */
	@PutMapping("update")
	@Permission("更新配置")
	public Result update(@RequestBody Model params){
		if(service.update(params)){
			return Result.Success("DBMS_CONFIG_UPDATE_SUCCESS");
		}else{
			return Result.Success("DBMS_CONFIG_UPDATE_ERROR");
		}
	}
	
	/**
	 * 获取系统配置
	 * @param request
	 * @return
	 */
	@GetMapping("get")
	@Permission("获取配置")
	public Result get(String code){
		Model model=service.get(code);
		return Result.Success(model);
	}
}
